<?php

namespace App\Webdisk\Model;

use Illuminate\Database\Eloquent\Model;

class StatInfo extends Model
{
    //
    protected $table = 'stat';
    public $timestamps = false;

    /**
     * 取系统运行状态属性
     * @param string 字段名
     * @return string|null
     */
    static function get($field){
        $data = self::where(['name'=>$field])->first();
        return $data ? $data["value"] : null;
    }

    static function getInt($field){
        return (int)self::get($field);
    }

    /**
     * 设置系统运行状态属性
     * @param string 字段名
     * @return boolean|int
     */
    static function set($field,$value){
        if(self::get($field)){
            return self::where(['name'=>$field])->update(['value'=>$value]);
        }else{
            return self::insert(['value'=>$value,'name'=>$field]);
        }
    }
}
